package com.googlecode.ocl2sqlcompiler;

/**
 * 
 * @author Renato Miceli
 * 
 */
public enum OCLBoolean {

	TRUE, FALSE, UNKNOWN;

	public OCLBoolean and(OCLBoolean val) {
		if (this == FALSE || val == FALSE) {
			return FALSE;
		}
		if (this == UNKNOWN || val == UNKNOWN) {
			return UNKNOWN;
		}
		return TRUE;
	}

	public OCLBoolean or(OCLBoolean val) {
		if (this == TRUE || val == TRUE) {
			return TRUE;
		}
		if (this == UNKNOWN || val == UNKNOWN) {
			return UNKNOWN;
		}
		return FALSE;
	}

	public OCLBoolean not() {
		switch (this) {
		case TRUE:
			return FALSE;
		case FALSE:
			return TRUE;
		default:
			return UNKNOWN;
		}
	}

	public OCLBoolean xor(OCLBoolean val) {
		return (this.and(val.not())).or(this.not().and(val));
	}

	public OCLBoolean implies(OCLBoolean val) {
		if (this == TRUE && val == FALSE) {
			return FALSE;
		}
		if (this == UNKNOWN || val == UNKNOWN) {
			return UNKNOWN;
		}
		return TRUE;
	}

	public String toSQL() {
		if (this == TRUE) {
			return "'t'";
		}
		if (this == FALSE) {
			return "'f'";
		}
		return null;
	}

}
